///
/// ArmyBodger 3
/// (c)2010 richyp
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArmyBodger.Core {
    /// <summary>
    /// Collection of EquipmentOption objects
    /// </summary>
    public class EquipmentOptionCollection : List<EquipmentOption> {
        /// <summary>
        /// Get an EquiptionOption by the name of the Equipment
        /// </summary>
        /// <param name="name">The name of the Equipment</param>
        /// <returns>The specified EquipmentOption or null</returns>
        public EquipmentOption this[string name] {
            get {
                foreach (EquipmentOption option in this) {
                    if (option.Equipment.Name == name) {
                        return option;
                    }
                }
                return null;
            }
        }
        /// <summary>
        /// Return a collection of all EquipmentOptions, that are currently
        /// equipped
        /// </summary>
        public EquipmentOptionCollection Equipped {
            get {
                EquipmentOptionCollection equipped = new EquipmentOptionCollection();
                foreach (EquipmentOption option in this) {
                    if (option.Equipped) {
                        equipped.Add(option);
                    }
                }
                return equipped;
            }
        }
        /// <summary>
        /// Copy this collection of EquipmentOption objects
        /// </summary>
        /// <returns>A new collection with new instances of the EquipmentOption objects</returns>
        public EquipmentOptionCollection Copy() {
            return EquipmentOptionCollection.Copy(this);
        }
        /// <summary>
        /// Static copy method that takes a source rather than this instance
        /// </summary>
        /// <param name="source">The collection of EquipmentOption objects to copy</param>
        /// <returns>A new collection with new instances of the EquipmentOption objects</returns>
        public static EquipmentOptionCollection Copy(EquipmentOptionCollection source) {
            EquipmentOptionCollection results = new EquipmentOptionCollection();
            foreach (EquipmentOption option in source) {
                results.Add(option.Copy());
            }
            return results;
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            foreach (EquipmentOption eq in Equipped)
            {
                sb.Append(eq.Equipment.Name + " ");
            }
            return sb.ToString();
        }
    }
}
